home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11826 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.6 KB  |  124 lines

  1. Path: kettle.magna.com.au!news
  2. From: peter@magna.com.au (Peter J Brock)
  3. Newsgroups: comp.lang.c++
  4. Subject: VC++ 4.0 Template bug?
  5. Date: Sat, 16 Mar 1996 12:09:51 GMT
  6. Organization: Me
  7. Message-ID: <4ieatm$ibs@kettle.magna.com.au>
  8. Reply-To: peter@magna.com.au
  9. NNTP-Posting-Host: enterprise.magna.com.au
  10. X-Newsreader: Forte Free Agent v0.55
  11.  
  12. /*
  13. The following code illustrates what I think is a bug in the
  14. implementation of templates in MS Visual C++ 4.0.
  15.  
  16. This is the greatly reduced code that reproduces the problem
  17. that I encountered when developing a matrix class based on the
  18. STL vector. This code does not use any STL classes.
  19.  
  20. The problems is that the member function A::test produces
  21. a compile time error for the line
  22.  
  23. fdTest() = 5.0; //error C2064: term does not evaluate to a function
  24.  
  25. This line also exist in main(), and produces no error.
  26. The work arround was to explicitly define the member function
  27.  
  28. inline double& VeryTesting<double>::operator ()()
  29.  
  30. This is commented out in the code, so just uncomment to see
  31. that it does indeed remedy the problem.
  32.  
  33. Note: this should not be required.
  34.  
  35. Questions;
  36. 1) Has anybody else had this problem?
  37. 2) What are some of the other template errors in MS Visual C++ 4.0?
  38. 3) Is it safe to use templates in VC++ 4.0 given the compiler gets
  39.    confused?
  40.  
  41. Note: In the process of producing this example I noticed other strange
  42. errors being reported. One was that the class was already defined.
  43.  
  44.  
  45. Cheers,
  46. Peter J Brock    http://www.magna.com.au/~peter
  47.  
  48.  
  49. */
  50.  
  51. //____________________________________________________________
  52. // test.cpp
  53.  
  54. template <class T>
  55. class VeryTesting
  56. {     
  57.     public: 
  58.         VeryTesting();
  59.  
  60.         T& operator()();
  61.  
  62.         T     m_T;
  63. };
  64.  
  65. template <class T>
  66. inline
  67. VeryTesting<T>::VeryTesting () 
  68. {
  69. }
  70.  
  71. template <class T>
  72. inline T& 
  73. VeryTesting<T>::operator ()()
  74. {
  75.     return m_T;
  76. }
  77.  
  78. /*  Uncomment this block of code and it all works! Why?
  79. inline double& 
  80. VeryTesting<double>::operator ()()
  81. {
  82.     return m_T;
  83. }
  84. */
  85.  
  86. class A
  87. {
  88.     public :
  89.         A(){}
  90.         ~A(){}
  91.  
  92.         VeryTesting<double>& test(VeryTesting<double>& fdTest)
  93.         {
  94.             fdTest() = 5.0; //error C2064: term does not evaluate to a function
  95.             return fdTest;
  96.         }
  97.  
  98. };
  99.  
  100. main()
  101. {
  102.     VeryTesting<double> f;
  103.     f() = 5.0;
  104.  
  105.     A aObject;
  106.     aObject.test(f);
  107. }
  108.  
  109. /*
  110.  
  111. Funny things happen with this module.
  112.  
  113. Try variations of this and you will see all manner of errors.
  114. In the attempt to minimize this sample I had errors telling me
  115. that the template class had previously been defined. Just where it
  116. could have been defined escapes me. Maybe MS has an undocumented
  117.  VeryTesting class which just happens to be templated based.
  118.  
  119.  
  120.  */
  121. //____________________________________________________________
  122.  
  123.  
  124.